home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / gnumake / pdmake.zoo / reader.c < prev    next >
C/C++ Source or Header  |  1991-09-25  |  3KB  |  135 lines

  1.     /***************************************************************\
  2.     *                                *
  3.     *  PDMAKE, Atari ST version                    *
  4.     *                                *
  5.     *  Adapted from mod.sources Vol 7 Issue 71, 1986-12-03.        *
  6.     *                                *
  7.     *  This port makes extensive use of the original net.sources    *
  8.     *  port by Jwahar Bammi.                    *
  9.     *                                *
  10.     *      Ton van Overbeek                        *
  11.     *      Email: TPC862@ESTEC.BITNET                *
  12.     *             TPC862%ESTEC.BITNET@WISCVM.WISC.EDU    (ARPA)    *
  13.     *             ...!mcvax!tpc862%estec.bitnet   (UUCP Europe)    *
  14.     *             ...!ucbvax!tpc862%estec.bitnet  (UUCP U.S.A.)    *
  15.     *             71450,3537  (CompuServe)                *
  16.     *                                *
  17.     \***************************************************************/
  18.  
  19. /*
  20.  *    Read in makefile
  21.  */
  22.  
  23.  
  24. #include <stdio.h>
  25. #include <ctype.h>
  26. #include "h.h"
  27.  
  28.  
  29. int    lineno;
  30.  
  31.  
  32. /*
  33.  *    Syntax error handler.  Print message, with line number, and exits.
  34.  */
  35. void
  36. error(msg, a1, a2, a3)
  37. char *    msg;
  38. {
  39.     fprintf(stderr, "%s: ", myname);
  40.     fprintf(stderr, msg, a1, a2, a3);
  41.     if (lineno)
  42.         fprintf(stderr, " near line %d", lineno);
  43.     fputc('\n', stderr);
  44.     exit(1);
  45. }
  46.  
  47.  
  48. /*
  49.  *    Read a line into the supplied string of length LZ.  Remove
  50.  *    comments, ignore blank lines. Deal with quoted (\) #, and
  51.  *    quoted newlines.  If EOF return TRUE.
  52.  */
  53. bool
  54. getline(str, fd)
  55. char *    str;
  56. FILE *    fd;
  57. {
  58.     register char *    p;
  59.     char *        q;
  60.     int            pos = 0;
  61.  
  62.  
  63.     for (;;)
  64.     {
  65.         if (fgets(str+pos, LZ-pos, fd) == (char *)0)
  66.             return TRUE;                /*  EOF  */
  67.  
  68.         lineno++;
  69.  
  70.         if ((p = index(str+pos, '\n')) == (char *)0)
  71.             error("Line too long");
  72.  
  73.         if (p[-1] == '\\')
  74.         {
  75.             p[-1] = '\n';
  76.             pos = p - str;
  77.             continue;
  78.         }
  79.  
  80.         p = str;
  81.         while (((q = index(p, '#')) != (char *)0) &&
  82.             (p != q) && (q[-1] == '\\'))
  83.         {
  84.             char    *a;
  85.  
  86.             a = q - 1;            /*  Del \ chr; move rest back  */
  87.             p = q;
  88.             while (*a++ = *q++)
  89.                 ;
  90.         }
  91.         if (q != (char *)0)
  92.         {
  93.             q[0] = '\n';
  94.             q[1] = '\0';
  95.         }
  96.  
  97.         p = str;
  98.         while (isspace(*p))        /*  Checking for blank  */
  99.             p++;
  100.  
  101.         if (*p != '\0')
  102.             return FALSE;
  103.         pos = 0;
  104.     }
  105. }
  106.  
  107.  
  108. /*
  109.  *    Get a word from the current line, surounded by white space.
  110.  *    Return a pointer to it. String returned has no white spaces
  111.  *    in it.
  112.  */
  113. char *
  114. gettok(ptr)
  115. char **ptr;
  116. {
  117.     register char *    p;
  118.  
  119.  
  120.     while (isspace(**ptr))        /*  Skip spaces  */
  121.         (*ptr)++;
  122.  
  123.     if (**ptr == '\0')            /*  Nothing after spaces  */
  124.         return NULL;
  125.  
  126.     p = *ptr;                /*  Word starts here  */
  127.  
  128.     while ((**ptr != '\0') && (!isspace(**ptr)))
  129.         (*ptr)++;            /*  Find end of word  */
  130.  
  131.     *(*ptr)++ = '\0';            /*  Terminate it  */
  132.  
  133.     return(p);
  134. }
  135.